package com.biboheart.adapter.support.enums;

import com.biboheart.adapter.support.BaseEnum;
import com.biboheart.adapter.support.EnumValueObject;

import java.util.ArrayList;
import java.util.List;

public enum LogicalEnum implements BaseEnum<String, String> {
    OPERATOR_LOGICAL_AND("&&", "与"),
    OPERATOR_LOGICAL_OR("||", "或"),
    OPERATOR_LOGICAL_NOT("!", "非"),
    OPERATOR_LOGICAL_GREATER(">", "大于"),
    OPERATOR_LOGICAL_GREATER_EQUAL(">=", "大于等于"),
    OPERATOR_LOGICAL_LESS("<", "小于"),
    OPERATOR_LOGICAL_LESS_EQUAL("<=", "小于等于"),
    OPERATOR_LOGICAL_EQUAL("==", "双等号"),
    OPERATOR_LOGICAL_EQUAL_SINGLE("=", "单等号"),
    OPERATOR_LOGICAL_EQUAL_NOT("!=", "不等"),
    ;
    private final String code;
    private final String desc;

    LogicalEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public String code() {
        return code;
    }

    @Override
    public String desc() {
        return desc;
    }

    public static LogicalEnum getOperator(String code) {
        LogicalEnum[] logicalEnums = values();
        for (LogicalEnum logicalEnum : logicalEnums) {
            if (logicalEnum.code().equals(code)) {
                return logicalEnum;
            }
        }
        return null;
    }

    public static boolean contains(String code) {
        LogicalEnum[] logicalEnums = values();
        for (LogicalEnum logicalEnum : logicalEnums) {
            if (logicalEnum.code().equals(code)) {
                return true;
            }
        }
        return false;
    }

    public static List<EnumValueObject<String, String>> list() {
        List<EnumValueObject<String, String>> list = new ArrayList<>();
        for (LogicalEnum operatorEnum : values()) {
            list.add(new EnumValueObject<>(operatorEnum.code(), operatorEnum.desc()));
        }
        return list;
    }
}
